package com.example.system.manger;


import com.example.core.constants.CacheConstants;
import com.example.redis.service.RedisService;
import com.example.system.domain.exam.Exam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class ExamCacheManager {

    @Autowired
    private RedisService redisService;

    public void addCache(Exam exam) {
        redisService.leftPushForList(getExamListKey(), exam.getExamId());
        redisService.setCacheMapValue(getDetailKey(), String.valueOf(exam.getExamId()), exam);
    }

    public void deleteCache(Long examId) {
        redisService.removeForList(getExamListKey(), examId);
        redisService.deleteCacheMapValue(getDetailKey(), String.valueOf(examId));
    }

    private String getExamListKey() {
        return CacheConstants.EXAM_NOT_STARTED_LIST;
    }

    private String getDetailKey() {
        return CacheConstants.EXAM_DETAIL;
    }
}
